﻿@model orienta.ViewModels.PersonaInfo
@{
    Layout = "~/Views/Shared/_LayoutPopUp.cshtml";
    ViewBag.Title = "Registro Dirección";
    var id = 0; 
}

<link href="@Url.Content("~/css/wick.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/redmond/jquery-ui-1.8.2.custom.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/redmond/jquery-ui-custom.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/ui-lightness/ui.jqgrid.css")" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .page {
    width: 99% !important;
    margin-left: auto;
    margin-right: auto;
}
    #main {
    padding: 5px 5px 5px 5px !important;
}
    </style>

    <script src="@Url.Content("~/Scripts/layout/jquery-1.8.0.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/ORI.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/grid.locale-es.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/layout/jquery.easyui.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/js/ubigeo.js")" type="text/javascript"></script>
<script src="@Url.Content("~/js/funciones.js")" type="text/javascript"></script>
<script type="text/javascript">
    window.onload = function () {
        cargarAutoCompleteUbigeo();
        CrearGridDirecciones();
        ListarDirecciones();
    };
    var ya = 1;
    var intervalo = window.setInterval(function () {
        if (dataUbigeo != null && dataUbigeo != undefined) {
            ya = 2;
        }
        if (ya == 2) {
            var dep = $("#hdnDepartamento").val();
            var pro = $("#hdnProvincia").val();
            var dis = $("#hdnDistrito").val();
            $("#PersonaDireccion_sUbigeoDepartamento").val(dep).change();
            $("#PersonaDireccion_sUbigeoProvincia").val(pro).change();
            $("#PersonaDireccion_sUbigeoDistrito").val(dis).change();
            clearInterval(intervalo);
        }
    }, 200);
    function Close() {
        opener.location.reload(false);
        self.close();
    }

    function CrearGridDirecciones() {
        $("#tabla").jqGrid({
           datatype:'local',
           colNames: ['nIdePersona', 'nSeqDirec', 'Estado', 'Nombre Vía', 'Nro Vía', 'Nro Dep', 'Nro Manzana'
        ,'Nro Lote','Nro Kilometro','Nro Bloque','Nro Etapa','nIdeTipoZona','Nombre Zona',
        'Centro Poblado', 'Ref 1', 'Ref 2', 'Fecha Inicio', 'Fecha Fin','nIdeTipoVia', 'nIdeCodUbigeo', 'Departamento', 'Provincia', 'Distrito',
            'nIdeTipoDir'],
            colModel: [
            { name: 'nIdePersona', index: 'nIdePersona', width: 40, align: "left",  hidden: true },
            { name: 'nSeqDirec', index: 'nSeqDirec', width: 40, align: "left",key: true, hidden: true },
            { name: 'Estado', index: 'Estado', align: 'left', width: 70 },
            { name: 'vNomVia', index: 'vNomVia', align: 'left', width: 70 },
            { name: 'vNumVia', index: 'vNumVia', align: 'left', width: 60 },
            { name: 'vNumDep', index: 'vNumDep', align: 'left', width: 60 },
            { name: 'vNumManza', index: 'vNumManza', align: 'left', width: 60 },
            { name: 'vNumLote', index: 'vNumLote', align: 'left', width: 60 },
            { name: 'vNumKilom', index: 'vNumKilom', align: 'left', width: 60 },
            { name: 'vNumBlock', index: 'vNumBlock', align: 'left', width: 60 },
            { name: 'vNumEtapa', index: 'vNumEtapa', align: 'left', width: 60 },
            { name: 'nIdeTipoZona', index: 'nIdeTipoZona', align: 'left', width: 60 },
            { name: 'vNomZona', index: 'vNomZona', align: 'left', width: 60 },
            { name: 'vCenPoblado', index: 'vCenPoblado', align: 'left', width: 60 },
            { name: 'vRefe1', index: 'vRefe1', align: 'left', width: 80 },
            { name: 'vRefe2', index: 'vRefe2', align: 'left', width: 80 },
            { name: 'dtFecIniVig', index: 'dtFecIniVig', align: 'left', width: 70, formatter: 'date', formatoptions: { srcformat: 'Y-m-d', newformat: 'd/m/Y'} },
            { name: 'dtFecFinVig', index: 'dtFecFinVig', align: 'left', width: 70, formatter: 'date', formatoptions: { srcformat: 'Y-m-d', newformat: 'd/m/Y'} },
            { name: 'nIdeTipoVia', index: 'nIdeTipoVia', hidden: true },
            { name: 'nIdeCodUbigeo', index: 'nIdeCodUbigeo', hidden: true },
            { name: 'departamento', index: 'departamento', align: 'left', width: 110 },
            { name: 'provincia', index: 'provincia', align: 'left', width: 120 },
            { name: 'distrito', index: 'distrito', align: 'left', width: 120 },
            { name: 'nIdeTipoDir', index: 'nIdeTipoDir', align: 'left', width: 90, hidden: true }
        ],
            sortorder: "desc",
            rowNum: 10,
            rowNumber:10,
            rowList: [5, 10, 20],
            cellsubmit: "clientArray",
            pager: "#barra",
            sortable: false, 
            scrollable: true,
            shrinkToFit: false,
            height: '160px',
            width: '600px',
            viewrecords: true,
            id: "id",
            caption: 'Direcciones',
            loadComplete: function () {
                var gr = jQuery('#tabla');
                fixGridSize(gr);
            }
        });
        jQuery("#tabla").jqGrid('navGrid', "#barra", { edit: false, add: false, del: false, search: false });

    }
    function ListarDirecciones() {
        $("#tabla").jqGrid("clearGridData");
        var id = $("#nIdePersona").val();
        var url = '@Url.Action("ListarDirecciones", "Solicitud")';
        var parametros = { id: id };
        var resultado = ORI.Ajax(url, parametros, false);
        if (resultado.Success) {
            $.each(resultado.Data, function (i, v) {
                var myData = { 
                    nIdePersona:v.nIdePersona,
                    nSeqDirec: v.nSeqDirec,
                    Estado: v.estado,
                    vNomVia:v.vNomVia,
                    vNumViav:v.vNumVia,
                    vNumDep:v.vNumDep,
                    vNumManza:v.vNumManza,
                    vNumLote:v.vNumLote,
                    vNumKilom:v.vNumKilom,
                    vNumBlock:v.vNumBlock,
                    vNumEtapa:v.vNumEtapa,
                    nIdeTipoZona:v.nIdeTipoZona,
                    vNomZona:v.vNomZona,
                    vCenPoblado:v.vCenPoblado,
                    vRefe1:v.vRefe1,
                    vRefe2:v.vRefe2,
                    dtFecIniVig:v.dtFecIniVig,
                    dtFecFinVig:v.dtFecFinVig,
                    nIdeTipoVia:v.nIdeTipoVia,
                    nIdeCodUbigeo:v.nIdeCodUbigeo,
                    departamento:v.departamento,
                    provincia:v.provincia,
                    distrito:v.distrito,
                    nIdeTipoDir:v.nIdeTipoDir
                };
                jQuery("#tabla").jqGrid('addRowData', i, myData);
            });
            $("#tabla").trigger("ReloadGrid");
        } else {
            alert(resultado.Message);
        }
    }
    var fixGridWidth = function (grid) {
        var gviewScrollWidth = grid[0].parentNode.parentNode.parentNode.scrollWidth;
        var mainWidth = jQuery('#main').width();
        var gridScrollWidth = grid[0].scrollWidth;
        var htable = jQuery('table.ui-jqgrid-htable', grid[0].parentNode.parentNode.parentNode);
        var scrollWidth = gridScrollWidth;
        if (htable.length > 0) {
            var hdivScrollWidth = htable[0].scrollWidth;
            if ((gridScrollWidth < hdivScrollWidth))
                scrollWidth = hdivScrollWidth; // max (gridScrollWidth, hdivScrollWidth)
        }
        if (gviewScrollWidth != scrollWidth || scrollWidth > mainWidth) {
            var newGridWidth = (scrollWidth <= mainWidth) ? scrollWidth : mainWidth;  // min (scrollWidth, mainWidth)
            // if the grid has no data, gridScrollWidth can be less then hdiv[0].scrollWidth
            if (newGridWidth != gviewScrollWidth)
                grid.jqGrid("setGridWidth", newGridWidth);
        }
    };

    var fixGridSize = function (grid) {
        this.fixGridWidth(grid);
    };
</script>

@using (Html.BeginForm()) {
    @Html.HiddenFor(m => m.nIdePersona)
    @Html.HiddenFor(m => m.sApellidoPaterno)
    @Html.HiddenFor(m => m.sApellidoMaterno)
    @Html.HiddenFor(m => m.sPrimerNombre)
    @Html.HiddenFor(m => m.sEmail)
    @Html.HiddenFor(m => m.sNumDoc)
    @Html.HiddenFor(m => m.dtFecNac)
    @Html.HiddenFor(m => m.nIdeGenero)
    <table class="tablaPrincipal_MIDIS"  width="100%" cellpadding="2" border="0"  cellspacing="0">
    <tr><td>
    <div id="listado" style="background-color:#EAEFF5">
    <table id="tabla">
    </table>
    <div id="barra">
    </div>
</div>
    </td></tr>
        <tr>
            <td><span style="background-color: #b55055; color: white;">PERSONA: </span>
            <div><p style="text-height: 14;">@ViewBag.NombrePersona</p></div>
                <table cellpadding="0" cellspacing="0" border="0"  width="98%">
                    <tr>
                        <td>
                            <table  class="tablaTitulo_MIDIS" style="width: 180PX;" cellpadding="2" cellspacing="0" border="0">
                                <tr>
                                    <td  align="center">
                                        <div id="divDireccion" class="divTitulo_MIDIS" style="width: 180PX;">
                                            <span style="background-color: #b50055; color: white;">[DIRECCI&Oacute;N DE LA PERSONA]</span>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table width="100%" class="tablaInterna_MIDIS" cellpadding="0">
                                <tr><td>&nbsp;</td></tr>
                                <tr>
                                    <td align="center">
                                    <table width="98%" border="1" cellpadding="5" cellspacing="0" class="tablaPrincipalSin">
                                        <tbody class="tituloTextNormal">
                                            <tr>
                                                <td>
                                                    <table width="100%" border="0" cellpadding="3" cellspacing="0">
                                                        <tr>
                                                            <td>Tipo V&iacute;a</td>
                                                            <td>Nombre de V&iacute;a</td>
                                                            <td>N&uacute;mero</td>
                                                            <td>Dept.</td>
                                                            <td>Interior</td>
                                                            <td>MZ</td>
                                                            <td>Lote</td>
                                                            <td>KM</td>
                                                            <td># block</td>
                                                            <td>Etapa</td>
                                                        </tr>
                                                        <tr>
                                                                                        <td>
                                                                                        @Html.DropDownListFor(m => m.PersonaDireccion.nIdeTipoVia, (IEnumerable<SelectListItem>)ViewBag.TipoVia, "--Seleccione--")
                                                                                        </td>
                                                                                        <td>
                                                                                        @Html.TextBoxFor(m => m.PersonaDireccion.sNombreVia, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "14", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;"})
                                                                                        </td>
                                                                                        <td>
                                                                                        @Html.TextBoxFor(m => m.PersonaDireccion.sNumeroVia, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "10", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;"})
                                                                                        </td>
                                                                                        <td>
                                                                                        @Html.TextBoxFor(m => m.PersonaDireccion.sDepartamento, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "10", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;"})
                                                                                        </td>
                                                                                        <td>
                                                                                        @Html.TextBoxFor(m => m.PersonaDireccion.sInterior, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "10", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;" })
                                                                                        </td>
                                                                                        <td>
                                                                                        @Html.TextBoxFor(m => m.PersonaDireccion.sManzana, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "10", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;" })
                                                                                        </td>
                                                                                        <td>
                                                                                        @Html.TextBoxFor(m => m.PersonaDireccion.sLote, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "10", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;"})
                                                                                        </td>
                                                                                        <td>
                                                                                        @Html.TextBoxFor(m => m.PersonaDireccion.sKm, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "10", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;"})
                                                                                        </td>
                                                                                        <td>
                                                                                        @Html.TextBoxFor(m => m.PersonaDireccion.sBlock, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "10", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;"})
                                                                                        </td>
                                                                                        <td>
                                                                                        @Html.TextBoxFor(m => m.PersonaDireccion.sEtapa, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "10", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;"})
                                                                                        </td>
                                                                                    </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                                        <tr>
                                                            <td>Tipo Zona</td>
                                                            <td>Nombre de Zona</td>
                                                            <td>Departamento</td>
                                                            <td>Provincia</td>
                                                            <td>Distrito</td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                @Html.DropDownListFor(m => m.PersonaDireccion.nIdeTipoZona, (IEnumerable<SelectListItem>)ViewBag.TipoZona, "--Seleccione--")
                                                            </td>
                                                            <td>
                                                                @Html.TextBoxFor(m => m.PersonaDireccion.sNombreZona, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "12", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;"})
                                                            </td>
                                                            <td>
                                                                @Html.DropDownListFor(m => m.PersonaDireccion.sUbigeoDepartamento, Enumerable.Empty<SelectListItem>(), new { onchange = "javascript:cargarProvincias(this);" })
                                                                @Html.Hidden("hdnDepartamento", Model.PersonaDireccion.sUbigeoDepartamento)
                                                            </td>
                                                            <td>
                                                                @Html.DropDownListFor(m => m.PersonaDireccion.sUbigeoProvincia, Enumerable.Empty<SelectListItem>(), new { onchange = "javascript:cargarDistritos(this);" })
                                                                @Html.Hidden("hdnProvincia", Model.PersonaDireccion.sUbigeoProvincia)
                                                            </td>
                                                            <td>
                                                                @Html.DropDownListFor(m => m.PersonaDireccion.sUbigeoDistrito, Enumerable.Empty<SelectListItem>())
                                                                @Html.Hidden("hdnDistrito", Model.PersonaDireccion.sUbigeoDistrito)
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                                        <tr>
                                                            <td>Centro Poblado</td>
                                                            <td>&nbsp;</td>
                                                            <td>Referencia &nbsp;(1)</td>
                                                            <td>&nbsp;</td>
                                                            <td>Referencia &nbsp;(2)</td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                @Html.TextBoxFor(m => m.PersonaDireccion.sCentroPoblado, new { @class = "cajaTextoMayuscula", @maxlength = "100", size = "12", onkeypress = "return validaCaracterV2(event);" })
                                                            </td>
                                                            <td>&nbsp;</td>
                                                            <td>
                                                                @Html.TextAreaFor(m => m.PersonaDireccion.sReferencia1, new {rows = 5, cols = 100, @class = "cajaTextoMayuscula", @maxlength = "100", size = "12", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;"})
                                                            </td>
                                                            <td>&nbsp;</td>
                                                            <td>
                                                                @Html.TextAreaFor(m => m.PersonaDireccion.sReferencia2, new { rows = 5, cols = 100, @class = "cajaTextoMayuscula", @maxlength = "100", size = "12", onkeypress = "return validaCaracterV2(event);", onpaste = "return false;" })
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </tr>
                                <tr><td>&nbsp;</td></tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table border="0" cellpadding="5" cellspacing="0" width="80%">
                                <tbody class="letraLink_MIDIS">
                                    <tr align="left">
                                        <td><b>campo obligatorio:</b>&nbsp;<span class="letraAsterisco">(*)</span></td>
                                        <td><input type="submit" value="Registrar"  name="btnNuevo" class="boton" /></td>
                                        <td></td>
                                        
                                    </tr>
                                    <tr>
                                    <td colspan="3" style="text-align: right;">
                                    <input type="button" value="Cerrar"  name="btnCancelar" class="boton" onclick="Close(); return true;" />
                                    </td>
                                    </tr>
                                </tbody>
                                
                            </table>
                        </td>
                        <div style="display: block; color:Green;"><b>@ViewBag.MsgConfirm</b></div>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
}

<div id="divUbigeo" style="display:none"></div>

